package project;

import java.io.*;
import java.util.Date;

/**
 * @Author: sun
 * @Description:负责读取数据
 * @Data: create in 15:47 2018/12/15
 * @Modfied by:
 */
public class Reader {
    private String url;

    public Reader(String urlParam) {
        this.url = urlParam;
    }

    public void read() throws IOException {
        BufferedReader br = null;
        File dataFile = new File(this.url);
        br = new BufferedReader(new FileReader(dataFile));
        String line = "";
        while ((line = br.readLine()) != null) {
            System.out.println("line: "+line);
        }
    }

    public void putInBloomFilter(Bloom bloom) throws IOException {
        BufferedReader br = null;
        File dataFile = new File(this.url);
        br = new BufferedReader(new FileReader(dataFile));
        String line = "";
        int count = 0;
        long timeStart = System.currentTimeMillis();
        System.out.println(timeStart);
        while ((line = br.readLine()) != null) {
            System.out.println(line);
            bloom.put(line);
            count++;
            if(count>2462000){
                System.out.println(bloom.bloomFilter.hashCode());
            }
//            System.out.println(bloom.bloomFilter.hashCode());
        }

        long timeEnd = System.currentTimeMillis();
        System.out.println("耗时: "+(timeEnd-timeStart));
        System.out.println("count: "+count);
        System.out.println("估计数量:"+bloom.bloomFilter.approximateElementCount());
        System.out.println(bloom.bloomFilter.hashCode());

    }
}
